<template>
  <a-modal
    title="编辑所属用户"
    :visible="visible"
    :destroyOnClose="true"
    @cancel="handleCancel"
    @ok="submit"
  >
    <a-spin :spinning="confirmLoading">
      选择：
      <SelectSale
        v-model="store_user_id"
        :position="position"
      />
    </a-spin>
  </a-modal>
</template>
<script>

import { SelectSale } from '@/components'
import * as Api from '@/api/presales_customer'
import { isEmpty } from '@/utils/util'

export default {
  name: 'Index',
  components: {
    SelectSale
  },
  data () {
    return {
      visible: false,
      position: 0,
      record: {},
      store_user_id: '',
      confirmLoading: false,

      psIds: ''
    }
  },
  methods: {
    open (item) {
      this.record = item
      this.visible = true
      this.$nextTick(() => {
        this.store_user_id = item.store_user_id
      })
    },
    batchOpen (psIds) {
      this.psIds = psIds
      // this.record = item
      this.visible = true
    },
    handleCancel () {
      this.store_user_id = ''
      this.psIds = ''
      this.visible = false
    },
    submit () {
      var api
      if (!isEmpty(this.psIds)) {
        api = Api.batchEdit({ apiId: this.psIds, form: { store_user_id: this.store_user_id } })
      } else {
        api = Api.edit({ apiId: this.record['pc_id'], form: { store_user_id: this.store_user_id } })
      }
      this.confirmLoading = true
      api.then(result => {
        // 显示成功
        this.$message.success(result.message, 1.5)
        // 关闭对话框
        this.handleCancel()
        // 通知父端组件提交完成了
        this.$emit('handleSubmit')
      })
        .finally(result => {
          this.confirmLoading = false
        })
    }

  }
}
</script>
<style scoped lang='less'>

</style>
